<template>
  <a :class="styleName" @click="aClicked">{{ words }}</a>
</template>

<script>
export default {
  name: 'PdfEnter',
  props: {
    src: {
      type: String,
      default: ''
    },
    words: {
      type: String,
      default: ''
    },
    styleName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      isPdf: true
    }
  },
  mounted() {
    this.isPdf = /\.pdf$/.test(this.src)
  },
  methods: {
    aClicked() {
      if (this.isPdf) {
        localStorage.pdfSrc = this.src
        const routeUrl = this.$router.resolve({
          path: `/home/pdf`
        })
        window.open(routeUrl.href, '_blank')
      } else {
        window.open(this.src, '_blank')
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
